import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue']
    }),
    Components({
      // dirs 指定组件所在位置 默认是 src/components
      dirs: [
        'src/components/',
        'src/views/home/components/',
        'src/views/category/components/',
        'src/views/goods/components/',
        'src/views/login/components/',
        'src/views/cart/components/',
        'src/views/member/pay/components/'
      ],
      // 配置需要将哪些后缀类型的文件进行自动按需导入 默认值为vue
      extensions: ['vue'],
      // 生成components.d.ts
      dts: true,
      // 遍历子目录
      deep: true
    })
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/styles/index.scss" as *;`
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    assetsInlineLimit: 10240
  },
  server: {
    port: 5173,
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: 'http://pcapi-xiaotuxian-front-devtest.itheima.net',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  }
})
